function dir = SAT_SST_func_IO(input,P)

   if strcmp(input,'home')
       dir = '/Users/duochan/Data/Testing/';                 % TODO
       
   elseif strcmp(input,'GHCN')     % input directory
       dir =  [SAT_SST_func_IO('home'),'GHCNmV4/'];          % TO CHECK
       
   elseif strcmp(input,'HadSST4')  % input directory
       dir = [SAT_SST_func_IO('home'),'HadSST4/'];           % TO CHECK

   elseif strcmp(input,'CMIP6')    % input directory
       dir = [SAT_SST_func_IO('home'),'CMIP6/'];             % TO CHECK

   elseif strcmp(input,'home')     % output directory
       dir = [SAT_SST_func_IO('home'),'SAT_SST_Output/'];    % TO CHECK

   elseif strcmp(input,'date')     % Version of GHCN to use
       dir = '20220519';
       
   elseif strcmp(input,'GHCN_processed')
       dir = [SAT_SST_func_IO('GHCN'),'matfiles_',P.app,...
                                        '_',SAT_SST_func_IO('date'),'/'];
   elseif strcmp(input,'data')
       
       app = [P.source,...
              '_',P.app,'_use_qcf_para_',num2str(P.use_qcf_para)...
              '_distance_',num2str(P.distance)];
          
       dir = [SAT_SST_func_IO('home'),app,'/'];       
   end

   if ~strcmp(input,'date')
       if ~exist(dir,'dir'),       mkdir(dir);   end
   end
end
